(function(t){var e;function i(t){this.InitUtil();this.dom={};this.bxTags={};this.EMPTY_IMAGE_SRC="/bitrix/images/1.gif";this.HTML5_TAGS=["abbr","article","aside","audio","bdi","canvas","command","datalist","details","figcaption","figure","footer","header","hgroup","keygen","mark","meter","nav","output","progress","rp","rt","ruby","svg","section","source","summary","time","track","video","wbr"];this.BLOCK_TAGS=["H1","H2","H3","H4","H5","H6","P","BLOCKQUOTE","DIV","SECTION","PRE"];this.NESTED_BLOCK_TAGS=["BLOCKQUOTE","DIV"];this.TABLE_TAGS=["TD","TR","TH","TABLE","TBODY","CAPTION","COL","COLGROUP","TFOOT","THEAD"];this.BBCODE_TAGS=["P","U","TABLE","TR","TD","TH","IMG","A","CENTER","LEFT","RIGHT","JUSTIFY"];this.HTML_ENTITIES=["&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;","&uml;","&copy;","&ordf;","&laquo;","&not;","&reg;","&macr;","&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;","&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;","&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;","&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;","&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;","&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;","&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;","&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;","&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;","&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;","&OElig;","&oelig;","&Scaron;","&scaron;","&Yuml;","&circ;","&tilde;","&ndash;","&mdash;","&lsquo;","&rsquo;","&sbquo;","&ldquo;","&rdquo;","&bdquo;","&dagger;","&Dagger;","&permil;","&lsaquo;","&rsaquo;","&euro;","&Alpha;","&Beta;","&Gamma;","&Delta;","&Epsilon;","&Zeta;","&Eta;","&Theta;","&Iota;","&Kappa;","&Lambda;","&Mu;","&Nu;","&Xi;","&Omicron;","&Pi;","&Rho;","&Sigma;","&Tau;","&Upsilon;","&Phi;","&Chi;","&Psi;","&Omega;","&alpha;","&beta;","&gamma;","&delta;","&epsilon;","&zeta;","&eta;","&theta;","&iota;","&kappa;","&lambda;","&mu;","&nu;","&xi;","&omicron;","&pi;","&rho;","&sigmaf;","&sigma;","&tau;","&upsilon;","&phi;","&chi;","&psi;","&omega;","&bull;","&hellip;","&prime;","&Prime;","&oline;","&frasl;","&trade;","&larr;","&uarr;","&rarr;","&darr;","&harr;","&part;","&sum;","&minus;","&radic;","&infin;","&int;","&asymp;","&ne;","&equiv;","&le;","&ge;","&loz;","&spades;","&clubs;","&hearts;"];if(!BX.browser.IsIE()){this.HTML_ENTITIES=this.HTML_ENTITIES.concat(["&thetasym;","&upsih;","&piv;","&weierp;","&image;","&real;","&alefsym;","&crarr;","&lArr;","&uArr;","&rArr;","&dArr;","&hArr;","&forall;","&exist;","&empty;","&nabla;","&isin;","&notin;","&ni;","&prod;","&lowast;","&prop;","&ang;","&and;","&or;","&cap;","&cup;","&there4;","&sim;","&cong;","&sub;","&sup;","&nsub;","&sube;","&supe;","&oplus;","&otimes;","&perp;","&sdot;","&lceil;","&rceil;","&lfloor;","&rfloor;","&lang;","&rang;","&diams;"])}this.SHORTCUTS={66:"bold",73:"italic",85:"underline"};this.KEY_CODES={backspace:8,enter:13,escape:27,space:32,delete:46,left:37,right:39,up:38,down:40,z:90,y:89,shift:16,ctrl:17,alt:18,cmd:91,cmdRight:93,pageUp:33,pageDown:34};this.INVISIBLE_SPACE="\ufeff";this.INVISIBLE_CURSOR="\u2060";this.NORMAL_WIDTH=1020;this.MIN_WIDTH=700;this.MIN_HEIGHT=100;this.MAX_HANDLED_FORMAT_LENGTH=5e4;this.MAX_HANDLED_FORMAT_TIME=500;this.iframeCssText="";this.InitConfig(this.CheckConfig(t));if(!t.lazyLoad){this.Init()}}i.prototype={Init:function(){if(this.inited)return;this.parser=new BXHtmlEditor.BXEditorParser(this);this.On("OnEditorInitedBefore",[this]);if(!this.BuildSceleton())return;this.HTMLStyler=r;this.dom.textarea=this.dom.textareaCont.appendChild(BX.create("TEXTAREA",{props:{className:"bxhtmled-textarea"}}));this.dom.pValueInput=BX("bxed_"+this.id);if(!this.dom.pValueInput){this.dom.pValueInput=this.dom.cont.appendChild(BX.create("INPUT",{props:{type:"hidden",id:"bxed_"+this.id,name:this.config.inputName}}))}this.dom.pValueInput.value=this.config.content;this.dom.form=this.dom.textarea.form||false;this.document=null;this.sandbox=this.CreateIframeSandBox();var t=this.sandbox.GetIframe();t.style.width="100%";t.style.height="100%";if(this.config.content){this.dom.textareaCont.style.opacity=0;this.dom.iframeCont.style.opacity=0}this.textareaView=new BXEditorTextareaView(this,this.dom.textarea,this.dom.textareaCont);this.iframeView=new BXEditorIframeView(this,this.dom.textarea,this.dom.iframeCont);this.synchro=new BXEditorViewsSynchro(this,this.textareaView,this.iframeView);if(this.bbCode){this.bbParser=new BXHtmlEditor.BXEditorBbCodeParser(this)}this.phpParser=new BXHtmlEditor.BXEditorPhpParser(this);this.components=new BXHtmlEditor.BXEditorComponents(this);this.styles=new h(this);this.overlay=new BXHtmlEditor.Overlay(this);this.BuildToolbar();if(this.showTaskbars){this.taskbarManager=new BXHtmlEditor.TaskbarManager(this,true);if(this.showComponents){this.componentsTaskbar=new BXHtmlEditor.ComponentsControl(this);this.taskbarManager.AddTaskbar(this.componentsTaskbar)}if(this.showSnippets){this.snippets=new BXHtmlEditor.BXEditorSnippets(this);this.snippetsTaskbar=new BXHtmlEditor.SnippetsControl(this,this.taskbarManager);this.taskbarManager.AddTaskbar(this.snippetsTaskbar)}this.taskbarManager.ShowTaskbar(this.showComponents?this.componentsTaskbar.GetId():this.snippetsTaskbar.GetId())}else{this.dom.taskbarCont.style.display="none"}this.contextMenu=new BXHtmlEditor.ContextMenu(this);if(this.config.showNodeNavi){this.nodeNavi=new BXHtmlEditor.NodeNavigator(this);this.nodeNavi.Show()}this.pasteControl=new BXHtmlEditor.PasteControl(this);this.InitEventHandlers();this.ResizeSceleton();if(this.showTaskbars&&this.config.taskbarShown){this.taskbarManager.Show(false)}this.inited=true;this.On("OnEditorInitedAfter",[this]);if(!this.CheckBrowserCompatibility()){this.dom.cont.parentNode.insertBefore(BX.create("DIV",{props:{className:"bxhtmled-warning"},text:BX.message("BXEdInvalidBrowser")}),this.dom.cont)}this.InitImageUploader();this.Show();BX.onCustomEvent(BXHtmlEditor,"OnEditorCreated",[this])},InitConfig:function(t){this.config=t;this.id=this.config.id;this.dialogs={};this.bbCode=!!this.config.bbCode;this.config.splitVertical=!!this.config.splitVertical;this.config.splitRatio=parseFloat(this.config.splitRatio);this.config.view=this.config.view||"wysiwyg";this.config.taskbarShown=!!this.config.taskbarShown;this.config.taskbarWidth=parseInt(this.config.taskbarWidth);this.config.showNodeNavi=this.config.showNodeNavi!==false;this.config.setFocusAfterShow=this.config.setFocusAfterShow!==false;this.cssCounter=0;this.iframeCssText=this.config.iframeCss;this.fileDialogsLoaded=this.bbCode||this.config.useFileDialogs===false;if(this.config.bbCodeTags&&this.bbCode){this.BBCODE_TAGS=this.config.bbCodeTags}if(this.config.minBodyWidth)this.MIN_WIDTH=parseInt(this.config.minBodyWidth);if(this.config.minBodyHeight)this.MIN_HEIGHT=parseInt(this.config.minBodyHeight);if(this.config.normalBodyWidth)this.NORMAL_WIDTH=parseInt(this.config.normalBodyWidth);this.normalWidth=this.NORMAL_WIDTH;if(!this.config.height)this.config.height=this.MIN_HEIGHT;if(!this.config.width)this.config.width=this.MIN_WIDTH;if(this.config.smiles){this.smilesIndex={};this.sortedSmiles=[];var e,i,s,n;for(e=0;e<this.config.smiles.length;e++){i=this.config.smiles[e];if(!i["codes"]||i["codes"]==i["code"]){this.smilesIndex[this.config.smiles[e].code]=i;this.sortedSmiles.push(i)}else if(i["codes"].length>0){n=i["codes"].split(" ");for(s=0;s<n.length;s++){this.smilesIndex[n[s]]=i;this.sortedSmiles.push({name:i.name,path:i.path,code:n[s]})}}}this.sortedSmiles=this.sortedSmiles.sort((function(t,e){return e.code.length-t.code.length}))}this.allowPhp=!!this.config.allowPhp;this.lpa=!this.config.allowPhp&&this.config.limitPhpAccess;this.templateId=this.config.templateId;this.componentFilter=this.config.componentFilter;this.showSnippets=this.config.showSnippets!==false;this.showComponents=this.config.showComponents!==false&&(this.allowPhp||this.lpa);this.showTaskbars=this.config.showTaskbars!==false&&(this.showSnippets||this.showComponents);this.templates={};this.templates[this.templateId]=this.config.templateParams},InitEventHandlers:function(){var e=this;BX.bind(this.dom.cont,"click",BX.proxy(this.OnClick,this));BX.bind(this.dom.cont,"mousedown",BX.proxy(this.OnMousedown,this));BX.bind(t,"resize",(function(){e.ResizeSceleton()}));if(BX.adminMenu){BX.addCustomEvent(BX.adminMenu,"onAdminMenuResize",(function(){e.ResizeSceleton()}))}BX.addCustomEvent(this,"OnIframeFocus",(function(){e.bookmark=null;if(e.statusInterval){clearInterval(e.statusInterval)}e.statusInterval=setInterval(BX.proxy(e.CheckCurrentStatus,e),500)}));BX.addCustomEvent(this,"OnIframeBlur",(function(){e.bookmark=null;if(e.statusInterval){clearInterval(e.statusInterval)}e.iframeView.stopBugusScroll=false}));BX.addCustomEvent(this,"OnTextareaFocus",(function(){e.bookmark=null;if(e.statusInterval){clearInterval(e.statusInterval)}}));BX.addCustomEvent(this,"OnSurrogateDblClick",(function(t,i,s,n){if(i){switch(i.tag){case"php":case"javascript":case"htmlcomment":case"iframe":case"style":e.GetDialog("Source").Show(i);break}}}));if(this.dom.form){BX.bind(this.dom.form,"submit",BX.proxy(this.OnSubmit,this));if(this.config.initAutosave!==false){setTimeout((function(){if(e.dom.form.BXAUTOSAVE){e.InitAutosaveHandlers()}}),100)}}BX.addCustomEvent(this,"OnSpecialcharInserted",(function(t){var i=e.GetLastSpecialchars(),s=BX.util.array_search(t,i);if(s!==-1){i=BX.util.deleteFromArray(i,s);i.unshift(t)}else{i.unshift(t);i.pop()}e.config.lastSpecialchars=i;e.SaveOption("specialchars",i.join("|"))}));this.parentDialog=BX.WindowManager.Get();if(this.parentDialog&&this.parentDialog.DIV&&BX.isNodeInDom(this.parentDialog.DIV)&&BX.findParent(this.dom.cont,(function(t){return t==e.parentDialog.DIV}))){BX.addCustomEvent(this.parentDialog,"onWindowResizeExt",(function(){e.ResizeSceleton()}))}if(this.config.autoResize){BX.addCustomEvent(this,"OnIframeKeyup",BX.proxy(this.AutoResizeSceleton,this));BX.addCustomEvent(this,"OnInsertHtml",BX.proxy(this.AutoResizeSceleton,this));BX.addCustomEvent(this,"OnIframeSetValue",BX.proxy(this.AutoResizeSceleton,this));BX.addCustomEvent(this,"OnFocus",BX.proxy(this.AutoResizeSceleton,this));BX.addCustomEvent(this,"OnSetViewAfter",BX.proxy(this.AutoResizeSceleton,this))}BX.addCustomEvent(this,"OnIframeKeyup",BX.proxy(this.CheckBodyHeight,this))},BuildSceleton:function(){var t=false;this.dom.cont=BX("bx-html-editor-"+this.id);if(this.dom.cont&&BX.isNodeInDom(this.dom.cont)){this.dom.toolbarCont=BX("bx-html-editor-tlbr-cnt-"+this.id);this.dom.toolbar=BX("bx-html-editor-tlbr-"+this.id);this.dom.areaCont=BX("bx-html-editor-area-cnt-"+this.id);this.dom.iframeCont=BX("bx-html-editor-iframe-cnt-"+this.id);this.dom.textareaCont=BX("bx-html-editor-ta-cnt-"+this.id);this.dom.resizerOverlay=BX("bx-html-editor-res-over-"+this.id);this.dom.splitResizer=BX("bx-html-editor-split-resizer-"+this.id);this.dom.splitResizer.style.display="none";this.dom.splitResizer.className=this.config.splitVertical?"bxhtmled-split-resizer-ver":"bxhtmled-split-resizer-hor";BX.bind(this.dom.splitResizer,"mousedown",BX.proxy(this.StartSplitResize,this));this.dom.taskbarCont=BX("bx-html-editor-tskbr-cnt-"+this.id);this.dom.navCont=BX("bx-html-editor-nav-cnt-"+this.id);this.dom.fileDialogsWrap=BX("bx-html-editor-file-dialogs-"+this.id);t=true}return t},ResizeSceleton:function(t,e,i){var s=this;if(this.expanded){var n=BX.GetWindowInnerSize(document);t=this.config.width=n.innerWidth;e=this.config.height=n.innerHeight}if(!t){t=this.config.width}if(!e){e=this.config.height}this.dom.cont.style.minWidth=this.MIN_WIDTH+"px";this.dom.cont.style.minHeight=this.MIN_HEIGHT+"px";var o,r;if(this.resizeTimeout){clearTimeout(this.resizeTimeout);this.resizeTimeout=null}if(t.toString().indexOf("%")!==-1){o=t;t=this.dom.cont.offsetWidth;if(!t){this.resizeTimeout=setTimeout((function(){s.ResizeSceleton(t,e,i)}),500);return}}else{if(t<this.MIN_WIDTH){t=this.MIN_WIDTH}o=t+"px"}this.dom.cont.style.width=o;this.dom.toolbarCont.style.width=o;if(e.toString().indexOf("%")!==-1){r=e;e=this.dom.cont.offsetHeight}else{if(e<this.MIN_HEIGHT){e=this.MIN_HEIGHT}r=e+"px"}this.dom.cont.style.height=r;var a=Math.max(t,this.MIN_WIDTH),h=Math.max(e,this.MIN_HEIGHT),l=this.toolbar.GetHeight(),d=this.showTaskbars?this.taskbarManager.GetWidth(true,a*.8):0,c=h-l-(this.config.showNodeNavi&&this.nodeNavi?this.nodeNavi.GetHeight():0),u=a-d;this.dom.areaCont.style.top=l?l+"px":0;this.SetAreaContSize(u,c,i);this.dom.taskbarCont.style.height=c+"px";this.dom.taskbarCont.style.width=d+"px";if(this.showTaskbars){this.taskbarManager.Resize(d,c)}this.toolbar.AdaptControls(t);this.On("OnEditorResizedAfter",[{width:t,height:e}])},CheckBodyHeight:function(){if(this.iframeView.IsShown()){var t=15,e,i=this.GetIframeDoc();if(i&&i.body){e=i.body.parentNode.offsetHeight-t*2;if(e<=20){setTimeout(BX.proxy(this.CheckBodyHeight,this),300)}else if(this.config.autoResize||e>i.body.offsetHeight){setTimeout((function(){e=i.body.parentNode.offsetHeight-t*2;i.body.style.minHeight=e+"px"}),300)}}}},GetSceletonSize:function(){return{width:this.dom.cont.offsetWidth,height:this.dom.cont.offsetHeight}},AutoResizeSceleton:function(){if(this.expanded||!this.IsShown()||this.iframeView.IsEmpty())return;var t=parseInt(this.config.autoResizeMaxHeight||0),e=parseInt(this.config.autoResizeMinHeight||50),i=this.dom.areaCont.offsetHeight,s,n=this;if(this.autoResizeTimeout){clearTimeout(this.autoResizeTimeout)}this.autoResizeTimeout=setTimeout((function(){s=n.GetHeightByContent();if(s>i){if(BX.browser.IsIOS()){t=Infinity}else if(!t||t<10){t=Math.round(BX.GetWindowInnerSize().innerHeight*.9)}s=Math.min(s,t);s=Math.max(s,e);n.SmoothResizeSceleton(s)}}),300)},GetHeightByContent:function(){var t=parseInt(this.config.autoResizeOffset||80),e;if(this.GetViewMode()=="wysiwyg"){var i=this.GetIframeDoc().body,s=i.lastChild,n=false;e=i.offsetHeight;while(true){if(!s){break}if(s.offsetTop){n=s.offsetTop+(s.offsetHeight||0);e=n+t;break}else{s=s.previousSibling}}var o=BX.GetWindowSize(this.GetIframeDoc());if(o.scrollHeight-o.innerHeight>5){e=Math.max(o.scrollHeight+t,e)}}else{e=(this.textareaView.element.value.split("\n").length+5)*17}return e},SmoothResizeSceleton:function(t){this.On("AutoResizeStarted");var e=this,i=this.GetSceletonSize(),s=i.height,n=0,o=t>s,r=50,a=5;if(!o)return;if(this.smoothResizeInt){clearInterval(this.smoothResizeInt)}this.smoothResizeInt=setInterval((function(){s+=Math.round(a*n);var i=s>=t;if(s>t){clearInterval(e.smoothResizeInt);if(s>t){s=t}}e.config.height=s;e.ResizeSceleton();if(i){e.On("AutoResizeFinished")}n++}),r)},SetAreaContSize:function(t,e,i){t+=2;this.dom.areaCont.style.width=t+"px";this.dom.areaCont.style.height=e+"px";if(i&&i.areaContTop){this.dom.areaCont.style.top=i.areaContTop+"px"}var s=3;if(this.currentViewName=="split"){function n(t,e,i){if(t<e){t=e}if(t>i){t=i}return t}var o=10,r,a,h;if(this.config.splitVertical==true){r=i&&i.deltaX?i.deltaX:0;a=n(t*this.config.splitRatio/(1+this.config.splitRatio)-r,o,t-o);h=t-a;this.dom.iframeCont.style.width=a-s+"px";this.dom.iframeCont.style.height=e+"px";this.dom.iframeCont.style.top=0;this.dom.iframeCont.style.left=0;this.dom.textareaCont.style.width=h-s+"px";this.dom.textareaCont.style.height=e+"px";this.dom.textareaCont.style.top=0;this.dom.textareaCont.style.left=a+"px";this.dom.splitResizer.className="bxhtmled-split-resizer-ver";this.dom.splitResizer.style.top=0;this.dom.splitResizer.style.left=a-3+"px";this.dom.textareaCont.style.height=e+"px"}else{r=i&&i.deltaY?i.deltaY:0;a=n(e*this.config.splitRatio/(1+this.config.splitRatio)-r,o,e-o);h=e-a;this.dom.iframeCont.style.width=t-s+"px";this.dom.iframeCont.style.height=a+"px";this.dom.iframeCont.style.top=0;this.dom.iframeCont.style.left=0;this.dom.textareaCont.style.width=t-s+"px";this.dom.textareaCont.style.height=h+"px";this.dom.textareaCont.style.top=a+"px";this.dom.textareaCont.style.left=0;this.dom.splitResizer.className="bxhtmled-split-resizer-hor";this.dom.splitResizer.style.top=a-3+"px";this.dom.splitResizer.style.left=0}if(i&&i.updateSplitRatio){this.config.splitRatio=a/h;this.SaveOption("split_ratio",this.config.splitRatio)}}else{this.dom.iframeCont.style.width=t-s+"px";this.dom.iframeCont.style.height=e+"px";this.dom.iframeCont.style.top=0;this.dom.iframeCont.style.left=0;this.dom.textareaCont.style.width=t-s+"px";this.dom.textareaCont.style.height=e+"px";this.dom.textareaCont.style.top=0;this.dom.textareaCont.style.left=0}},BuildToolbar:function(){this.toolbar=new BXHtmlEditor.Toolbar(this,this.GetTopControls())},GetTopControls:function(){this.On("GetTopButtons",[t.BXHtmlEditor.Controls]);return t.BXHtmlEditor.Controls},CreateIframeSandBox:function(){return new s(BX.proxy(this.OnCreateIframe,this),{editor:this,cont:this.dom.iframeCont})},OnCreateIframe:function(){if(!document.body.contains(this.dom.iframeCont)){return}this.On("OnCreateIframeBefore");this.iframeView.OnCreateIframe();this.selection=new n(this);this.action=new BXEditorActions(this);this.config.content=this.dom.pValueInput.value;this.SetContent(this.config.content,true);this.undoManager=new a(this);this.action.Exec("styleWithCSS",false,true);this.iframeView.InitAutoLinking();if(this.config.view!="wysiwyg"){var t,e=false,i=false,s=this.toolbar.GetControlsMap();if(this.config.view=="split"){for(t=0;t<s.length;t++){if(s[t]&&s[t].id=="ChangeView"){e=true;break}}if(!e)this.config.view="wysiwyg"}if(this.config.view!="wysiwyg"){for(t=0;t<s.length;t++){if(s[t]&&(s[t].id=="BbCode"||s[t].id=="ChangeView")){i=true;break}}if(!i)this.config.view="wysiwyg"}}this.SetView(this.config.view,false);if(this.config.setFocusAfterShow!==false){this.Focus(false)}this.sandbox.inited=true;this.On("OnCreateIframeAfter",[this])},GetDialog:function(e,i){if(!this.dialogs[e]&&t.BXHtmlEditor.dialogs[e])this.dialogs[e]=new t.BXHtmlEditor.dialogs[e](this,i);return this.dialogs[e]||null},Show:function(){this.dom.cont.style.display=""},Hide:function(){this.dom.cont.style.display="none"},IsShown:function(){return this.inited&&this.dom.cont.style.display!=="none"&&this.dom.cont.offsetWidth>0&&BX.isNodeInDom(this.dom.cont)},SetView:function(t,e){this.On("OnSetViewBefore");if(t=="split"&&this.bbCode)t="wysiwyg";if(this.currentViewName!=t){if(t=="wysiwyg"){this.iframeView.Show();this.textareaView.Hide();this.dom.splitResizer.style.display="none";this.CheckBodyHeight()}else if(t=="code"){this.iframeView.Hide();this.textareaView.Show();this.CheckCurrentStatus(false);this.dom.splitResizer.style.display="none"}else if(t=="split"){this.textareaView.Show();this.iframeView.Show();this.dom.splitResizer.style.display="";this.CheckBodyHeight()}this.currentViewName=t}if(e!==false){this.SaveOption("view",t)}this.ResizeSceleton();this.On("OnSetViewAfter")},GetViewMode:function(){return this.currentViewName},SetContent:function(t,e){this.On("OnSetContentBefore");if(this.bbCode){var i=this.bbParser.Parse(t);this.iframeView.SetValue(i,e);if(i!==t||i.indexOf("[")<0){this.dom.textareaCont.style.opacity=1;this.dom.iframeCont.style.opacity=1}}else{this.iframeView.SetValue(t,e);this.dom.textareaCont.style.opacity=1;this.dom.iframeCont.style.opacity=1}this.textareaView.SetValue(t,false);this.On("OnSetContentAfter")},Focus:function(t){if(this.currentViewName=="wysiwyg"){this.iframeView.Focus(t)}else if(this.currentViewName=="code"){this.textareaView.Focus(t)}else if(this.currentViewName=="split"){if(this.synchro.GetSplitMode()=="wysiwyg"){this.iframeView.Focus(t)}else{this.textareaView.Focus(t)}}this.On("OnFocus");return this},SaveContent:function(){if(this.currentViewName=="wysiwyg"||this.currentViewName=="split"&&this.synchro.GetSplitMode()=="wysiwyg"){this.synchro.lastIframeValue="";this.synchro.FromIframeToTextarea(true,true)}else{this.textareaView.SaveValue()}},GetContent:function(){this.SaveContent();return this.textareaView.GetValue()},IsExpanded:function(){return this.expanded},Expand:function(e){if(!e){e=!this.expanded}this.expanded=e;const i=BX.GetWindowInnerSize(document);let s,n,o,r,a,h,l,d;if(e){const e=BX.GetWindowScrollPos(document);const c=this.dom.cont.getBoundingClientRect();s=this.dom.cont.offsetWidth;n=this.dom.cont.offsetHeight;o=c.top;r=c.left;a=i.innerWidth;h=i.innerHeight;l=0;d=0;this.savedSize={width:s,height:n,top:o,left:r,scrollLeft:e.scrollLeft,scrollTop:e.scrollTop,configWidth:this.config.width,configHeight:this.config.height};this.savedStyle={position:this.dom.cont.style.position,zIndex:this.dom.cont.style.zIndex};this.config.width=a;this.config.height=h;this.dummieDiv=BX.create("DIV");this.dummieDiv.style.width=s+"px";this.dummieDiv.style.height=n+"px";this.dom.cont.parentNode.insertBefore(this.dummieDiv,this.dom.cont);this.savedParentOpacity=[];this.savedParentPosition=[];let u=this.dom.cont.parentNode;while(u&&u!==document){if(parseInt(t.getComputedStyle(u).getPropertyValue("opacity"))<1){let t="";if(parseInt(u.style.opacity)<1){t=u.style.opacity}this.savedParentOpacity.push({parent:u,opacity:t});u.style.opacity="1"}if(t.getComputedStyle(u).getPropertyValue("position")==="relative"&&parseInt(t.getComputedStyle(u).getPropertyValue("z-index"))>0){let t="";if(u.style.position==="relative"){t=u.style.position}this.savedParentPosition.push({parent:u,position:t});u.style.position="static"}if(t.getComputedStyle(u).getPropertyValue("will-change").includes("height")){u.style.willChange="unset"}u=u.parentNode}this.dom.cont.style.setProperty("background","white","important");this.dom.cont.style.position="fixed";this.dom.cont.style.zIndex=999;BX.addCustomEvent(this,"OnIframeKeydown",BX.proxy(this.CheckEscCollapse,this));BX.bind(document.body,"keydown",BX.proxy(this.CheckEscCollapse,this));BX.bind(t,"scroll",BX.proxy(this.PreventScroll,this))}else{s=this.dom.cont.offsetWidth;n=this.dom.cont.offsetHeight;o=0;r=0;a=this.savedSize.width;h=this.savedSize.height;l=this.savedSize.top;d=this.savedSize.left;BX.removeCustomEvent(this,"OnIframeKeydown",BX.proxy(this.CheckEscCollapse,this));BX.unbind(document.body,"keydown",BX.proxy(this.CheckEscCollapse,this));BX.unbind(t,"scroll",BX.proxy(this.PreventScroll,this))}this.dom.cont.style.width=s+"px";this.dom.cont.style.height=n+"px";this.dom.cont.style.top=o+"px";this.dom.cont.style.left=r+"px";var c=this;this.expandAnimation=new BX.easing({duration:300,start:{height:n,width:s,top:o,left:r},finish:{height:h,width:a,top:l,left:d},transition:BX.easing.makeEaseOut(BX.easing.transitions.quart),step:function(t){c.dom.cont.style.width=t.width+"px";c.dom.cont.style.height=t.height+"px";c.dom.cont.style.top=t.top+"px";c.dom.cont.style.left=t.left+"px";c.ResizeSceleton(t.width,t.height)},complete:function(){c.dom.cont.style.width=a+"px";c.dom.cont.style.height=h+"px";c.dom.cont.style.top=l+"px";c.dom.cont.style.left=d+"px";if(!e){let t=c.dom.cont.parentNode;while(t&&t!==document){if(t.style.willChange==="unset"){t.style.willChange=""}t=t.parentNode}for(const t of c.savedParentOpacity){t.parent.style.opacity=t.opacity}for(const t of c.savedParentPosition){t.parent.style.position=t.position}c.dummieDiv.remove();c.dom.cont.style.position=c.savedStyle.position;c.dom.cont.style.zIndex=c.savedStyle.zIndex;c.dom.cont.style.width="";c.dom.cont.style.height="";c.dom.cont.style.top="";c.dom.cont.style.left="";c.config.width=c.savedSize.configWidth;c.config.height=c.savedSize.configHeight}c.ResizeSceleton();c.CheckAndReInit()}});this.expandAnimation.animate()},CheckEscCollapse:function(t,e,i,s){if(!e){e=t.keyCode}if(this.IsExpanded()&&e==this.KEY_CODES["escape"]&&!this.IsPopupsOpened()){this.Expand(false);return BX.PreventDefault(t)}},PreventScroll:function(e){t.scrollTo(this.savedSize.scrollLeft,this.savedSize.scrollTop);return BX.PreventDefault(e)},IsPopupsOpened:function(){return!!(this.dialogShown||this.popupShown||this.contextMenuShown||this.overlay.bShown)},ReInitIframe:function(t){this.sandbox.InitIframe(null,(()=>{this.iframeView.OnCreateIframe();this.synchro.StopSync();this.synchro.lastTextareaValue="";this.synchro.FromTextareaToIframe(true);this.synchro.StartSync();this.iframeView.ReInit();this.selection.lastCheckedRange=null;if(this.config.setFocusAfterShow!==false){this.Focus()}if(typeof t==="function"){t()}this.On("OnAfterIframeInit",[this])}))},CheckAndReInit:function(t){if(this.sandbox.inited){var e=this.sandbox.GetWindow();if(e){var i=this.sandbox.GetDocument();if(i!==this.iframeView.document||!i.head||i.head.innerHTML==""){this.iframeView.document=i;this.iframeView.element=i.body;this.ReInitIframe((()=>{if(t!==undefined){this.SetContent(t,true);this.CheckBodyHeight()}}))}else if(i.body){i.body.style.minHeight=""}}else{throw new Error("HtmlEditor: CheckAndReInit error iframe isn't in the DOM")}}if(t!==undefined){this.SetContent(t,true);this.CheckBodyHeight()}},Disable:function(){},Enable:function(){},CheckConfig:function(t){if(t.content===undefined){t.content=""}return t},GetInnerHtml:function(t){var e="%7E",i="&amp;",s=t.innerHTML;if(s.indexOf(i)!==-1||s.indexOf(e)!==-1){s=s.replace(/(?:href|src)\s*=\s*("|')([\s\S]*?)(\1)/gi,(function(t){t=t.replace(/%7E/gi,"~");t=t.replace(/&amp;/gi,"&");return t}))}s=s.replace(/(?:title|alt)\s*=\s*("|')([\s\S]*?)(\1)/gi,(function(t){t=t.replace(/</g,"&lt;");t=t.replace(/>/g,"&gt;");return t}));if(this.bbCode){s=s.replace(/[\s\n\r]*?<!--[\s\S]*?-->[\s\n\r]*?/gi,"")}return s},InitUtil:function(){var e=this;this.util={};if("textContent"in document.documentElement){this.util.SetTextContent=function(t,e){t.textContent=e};this.util.GetTextContent=function(t){return t.textContent}}else if("innerText"in document.documentElement){this.util.SetTextContent=function(t,e){t.innerText=e};this.util.GetTextContent=function(t){return t.innerText}}else{this.util.SetTextContent=function(t,e){t.nodeValue=e};this.util.GetTextContent=function(t){return t.nodeValue}}this.util.AutoCloseTagSupported=function(){var t=document.createElement("div"),i,s;t.innerHTML="<p><div></div>";s=t.innerHTML.toLowerCase();i=s==="<p></p><div></div>"||s==="<p><div></div></p>";e.util.AutoCloseTagSupported=function(){return i};return i};this.util.FirstLetterSupported=function(){var t=!BX.browser.IsChrome()&&!BX.browser.IsSafari();e.util.FirstLetterSupported=function(){return t};return t};this.util.CheckGetAttributeTruth=function(){var t=document.createElement("td"),i=t.getAttribute("rowspan")!="1";e.util.CheckGetAttributeTruth=function(){return i};return i};this.util.CheckHTML5Support=function(t){if(!t){t=document}var i=false,s="<article>bitrix</article>",n=t.createElement("div");n.innerHTML=s;i=n.innerHTML.toLowerCase()===s;e.util.CheckHTML5Support=function(){return i};return i};this.util.CheckHTML5FullSupport=function(t){if(!t){t=document}var i,s=e.GetHTML5Tags(),n=false,o=t.createElement("div");for(var r=0;r<s.length;r++){i="<"+s[r]+">bitrix</"+s[r]+">";o.innerHTML=i;n=o.innerHTML.toLowerCase()===i;if(!n){break}}e.util.CheckHTML5FullSupport=function(){return n};return n};this.util.GetEmptyImage=function(){return e.EMPTY_IMAGE_SRC};this.util.CheckDataTransferSupport=function(){var i=false;try{i=!!(t.Clipboard||t.DataTransfer).prototype.getData}catch(t){}e.util.CheckDataTransferSupport=function(){return i};return i};this.util.CheckImageSelectSupport=function(){var t=!(BX.browser.IsChrome()||BX.browser.IsSafari());e.util.CheckImageSelectSupport=function(){return t};return t};this.util.CheckPreCursorSupport=function(){var t=!(BX.browser.IsIE()||BX.browser.IsIE10()||BX.browser.IsIE11());e.util.CheckPreCursorSupport=function(){return t};return t};this.util.Refresh=function(t){if(t&&t.parentNode){var i="bx-editor-refresh";BX.addClass(t,i);BX.removeClass(t,i);if(BX.browser.IsFirefox()){try{var s,n=t.ownerDocument,o=n.getElementsByTagName("I"),r=o.length;for(s=0;s<o.length;s++){o[s].setAttribute("data-bx-orgig-i",true)}n.execCommand("italic",false,null);n.execCommand("italic",false,null);var a=n.getElementsByTagName("I");if(a.length!==r){for(s=0;s<a.length;s++){if(a[s].getAttribute("data-bx-orgig-i")){a[s].removeAttribute("data-bx-orgig-i")}else{e.util.ReplaceWithOwnChildren(a[s])}}}}catch(t){}}}};this.util.addslashes=function(t){t=t.replace(/\\/g,"\\\\");t=t.replace(/"/g,'\\"');return t};this.util.stripslashes=function(t){t=t.replace(/\\"/g,'"');t=t.replace(/\\\\/g,"\\");return t};this.util.ReplaceNode=function(t,e){t.parentNode.insertBefore(e,t);t.parentNode.removeChild(t);return e};this.util.spaceUrlEncode=function(t){t=t.replace(/ /g,"%20");return t};this.util.spaceUrlDecode=function(t){t=t.replace(/%20/g," ");return t};this.util.DocumentHasTag=function(t,i){var s={},n=e.id+":"+i,o=s[n];if(!o)o=s[n]=t.getElementsByTagName(i);return o.length>0};this.util.IsSplitPoint=function(t,e){var i=e>0&&e<t.childNodes.length;if(rangy.dom.isCharacterDataNode(t)){if(e==0)i=!!t.previousSibling;else if(e==t.length)i=!!t.nextSibling;else i=true}return i};this.util.SplitNodeAt=function(t,i,s){var n;if(rangy.dom.isCharacterDataNode(i)){if(s==0){s=rangy.dom.getNodeIndex(i);i=i.parentNode}else if(s==i.length){s=rangy.dom.getNodeIndex(i)+1;i=i.parentNode}else{n=rangy.dom.splitDataNode(i,s)}}if(!n){n=i.cloneNode(false);if(n.id){n.removeAttribute("id")}var o;while(o=i.childNodes[s]){n.appendChild(o)}rangy.dom.insertAfter(n,i)}if(i&&i.nodeName=="BODY"){return n}return i==t?n:e.util.SplitNodeAt(t,n.parentNode,rangy.dom.getNodeIndex(n))};this.util.ReplaceWithOwnChildren=function(t){var e=t.parentNode;while(t.firstChild){e.insertBefore(t.firstChild,t)}e.removeChild(t)};this.util.IsBlockElement=function(t){var e=BX.style(t,"display");return e&&BX.type.isString(e)&&e.toLowerCase()==="block"};this.util.IsBlockNode=function(t){return t&&t.nodeType==1&&BX.util.in_array(t.nodeName,e.GetBlockTags())};this.util.CopyAttributes=function(t,e,i){if(e&&i){var s,n,o=t.length;for(n=0;n<o;n++){s=t[n];if(e[s])i[s]=e[s]}}};this.util.RenameNode=function(t,i){var s=t.ownerDocument.createElement(i),n;while(n=t.firstChild)s.appendChild(n);e.util.CopyAttributes(["align","className"],t,s);if(t.style.cssText!=""){s.style.cssText=t.style.cssText}t.parentNode.replaceChild(s,t);return s};this.util.GetInvisibleTextNode=function(){return e.iframeView.document.createTextNode(e.INVISIBLE_SPACE)};this.util.IsEmptyNode=function(t,i,s){var n;if(t.nodeType==3){n=t.data===""||t.data===e.INVISIBLE_SPACE||t.data==="\n"&&i;if(!n&&s&&t.data.toString().match(/^[\s\n\r\t]+$/gi)){n=true}}else if(t.nodeType==1){n=t.innerHTML===""||t.innerHTML===e.INVISIBLE_SPACE;if(!n&&s&&t.innerHTML.toString().match(/^[\s\n\r\t]+$/gi)){n=true}}return n};var i=document.documentElement;if("textContent"in i){this.util.SetTextContent=function(t,e){t.textContent=e};this.util.GetTextContent=function(t){return t.textContent}}else if("innerText"in i){this.util.SetTextContent=function(t,e){t.innerText=e};this.util.GetTextContent=function(t){return t.innerText}}else{this.util.SetTextContent=function(t,e){t.nodeValue=e};this.util.GetTextContent=function(t){return t.nodeValue}}this.util.GetTextContentEx=function(t){var i,s,n=[],o=t.cloneNode(true),r=o.getElementsByTagName("SCRIPT"),a=o.getElementsByTagName("A");for(i=r.length-1;i>=0;i--){BX.remove(r[i])}for(i=a.length-1;i>=0;i--){var h=a[i].href;if(h.toLowerCase().indexOf("javascript:")!==-1){e.util.ReplaceNode(a[i],a[i].ownerDocument.createTextNode(e.util.GetTextContent(a[i])))}else{n.push('<a href="'+a[i].href+'">'+e.util.GetTextContent(a[i])+"</a>");e.util.ReplaceNode(a[i],a[i].ownerDocument.createTextNode("#BX~TMP~LINK"+(n.length-1)+"#"))}}s=e.util.GetTextContent(o);if(n.length>0){s=s.replace(/#BX~TMP~LINK(\d+)#/gi,(function(t,e){return n[e]||""}))}return s};this.util.RgbToHex=function(t){if(!t)t="";if(t.search("rgb")!==-1){function e(t){return("0"+parseInt(t).toString(16)).slice(-2)}t=t.replace(/rgba\(0,\s*0,\s*0,\s*0\)/gi,"transparent");t=t.replace(/rgba?\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})(?:,\s*([\d\.]{1,3}))?\)/gi,(function(t,i,s,n,o){return"#"+e(i)+e(s)+e(n)}))}return t};this.util.CheckCss=function(t,e,i){var s=true,n;for(n in e){if(e.hasOwnProperty(n)){if(t.style[n]!=""){s=s&&(i?t.style[n]==e[n]:true)}else{s=false}}}return s};this.util.SetCss=function(t,e){if(t&&e&&typeof e=="object"){for(var i in e){if(e.hasOwnProperty(i)){t.style[i]=e[i]}}}};this.util.InsertAfter=function(t,e){return rangy.dom.insertAfter(t,e)};this.util.GetNodeDomOffset=function(t){var e=0;while(t.parentNode&&t.parentNode.nodeName!=="BODY"){t=t.parentNode;e++}return e};this.util.CheckSurrogateNode=function(t){return e.phpParser.CheckParentSurrogate(t)};this.util.CheckSurrogateDd=function(t){return e.phpParser.CheckSurrogateDd(t)};this.util.GetPreviousNotEmptySibling=function(t){var i=t.previousSibling;while(i&&i.nodeType==3&&e.util.IsEmptyNode(i,true,true)){i=i.previousSibling}return i};this.util.GetNextNotEmptySibling=function(t){var i=t.nextSibling;while(i&&i.nodeType==3&&e.util.IsEmptyNode(i,true,true)){i=i.nextSibling}return i};this.util.IsEmptyLi=function(t){if(t&&t.nodeName=="LI"){return e.util.IsEmptyNode(t,true,true)||t.innerHTML.toLowerCase()=="<br>"}return false};this.util.FindParentEx=function(t,e,i){if(BX.checkNode&&BX.checkNode(t,e))return t;return BX.findParent(t,e,i)};this.util.IsEmptyObject=function(t){for(var e in t){if(t.hasOwnProperty(e)){return false}}return true};this.util.GetNextSibling=function(t){var e=t.nextSibling;while(e&&e.nodeType==3&&e.nodeValue=="\ufeff"&&e.nextSibling){e=e.nextSibling}return e||null}},Parse:function(t,e,i){e=!!e;this.content=t;this.On("OnParse",[e]);if(e){this.content=this.parser.Parse(this.content,this.GetParseRules(),this.GetIframeDoc(),true,e);if((i===true||this.textareaView.IsShown())&&!this.bbCode){this.content=this.FormatHtml(this.content)}this.content=this.phpParser.ParseBxNodes(this.content)}else{this.content=this.phpParser.ParsePhp(this.content);this.content=this.parser.Parse(this.content,this.GetParseRules(),this.GetIframeDoc(),true,e)}this.On("OnAfterParse",[e]);return this.content},On:function(t,e){BX.onCustomEvent(this,t,e||[])},GetIframeDoc:function(){if(!this.document){this.document=this.sandbox.GetDocument();BX.addCustomEvent(this,"OnIframeReInit",BX.proxy((function(){this.document=this.sandbox.GetDocument()}),this))}return this.document},GetParseRules:function(){this.rules=e;this.On("OnGetParseRules");var t=this;this.GetParseRules=function(){return t.rules};return this.rules},GetHTML5Tags:function(){return this.HTML5_TAGS},GetBlockTags:function(){return this.BLOCK_TAGS},SetBxTag:function(t,e){var i;if(e.id||t&&t.id)i=e.id||t.id;if(!i){i="bxid"+Math.round(Math.random()*1e9)}else{if(this.bxTags[i]){if(!e.tag)e.tag=this.bxTags[i].tag}}e.id=i;if(t)t.id=e.id;this.bxTags[e.id]=e;return e.id},GetBxTag:function(t){var e;if(typeof t=="object"&&t&&t.id)e=t.id;else e=t;if(e){if(typeof e!="string"&&e.id)e=e.id;if(e&&e.length>0&&this.bxTags[e]&&this.bxTags[e].tag){this.bxTags[e].tag=this.bxTags[e].tag.toLowerCase();return this.bxTags[e]}}return{tag:false}},OnMousedown:function(t){var e=t.target||t.srcElement;if(e&&(e.getAttribute||e.parentNode)){var i=this,s=e.getAttribute("data-bx-type");if(!s){e=BX.findParent(e,(function(t){return t==i.dom.cont||t.getAttribute&&t.getAttribute("data-bx-type")}),this.dom.cont);s=e&&e.getAttribute?e.getAttribute("data-bx-type"):null}if(s=="action"){return BX.PreventDefault(t)}}return true},OnClick:function(t){var e=t.target||t.srcElement,i=e&&e.getAttribute?e.getAttribute("data-bx-type"):false;this.On("OnClickBefore",[{e:t,target:e,bxType:i}]);this.CheckCommand(e)},CheckCommand:function(t){if(t&&(t.getAttribute||t.parentNode)){var e=this,i=t.getAttribute("data-bx-type");if(!i){t=BX.findParent(t,(function(t){return t==e.dom.cont||t.getAttribute&&t.getAttribute("data-bx-type")}),this.dom.cont);i=t&&t.getAttribute?t.getAttribute("data-bx-type"):null}if(i=="action"){var s=t.getAttribute("data-bx-action"),n=t.getAttribute("data-bx-value");if(this.action.IsSupported(s)){this.action.Exec(s,n)}}}},SetSplitMode:function(t,e){this.config.splitVertical=!!t;if(e!==false){this.SaveOption("split_vertical",this.config.splitVertical?1:0)}this.SetView("split",e)},GetSplitMode:function(){return this.config.splitVertical},StartSplitResize:function(t){this.dom.resizerOverlay.style.display="block";var e=0,i=0,s=BX.GetWindowScrollPos(),n=t.clientX+s.scrollLeft,o=t.clientY+s.scrollTop,r=this;function a(t,a){var h=t.clientX+s.scrollLeft,l=t.clientY+s.scrollTop;if(n==h&&o==l){return}e=n-h;i=o-l;r.ResizeSceleton(0,0,{deltaX:e,deltaY:i,updateSplitRatio:a})}function h(t){a(t,true);BX.unbind(document,"mousemove",a);BX.unbind(document,"mouseup",h);r.dom.resizerOverlay.style.display="none"}BX.bind(document,"mousemove",a);BX.bind(document,"mouseup",h)},Request:function(t){if(!t.url)t.url=this.config.actionUrl;if(t.bIter!==false)t.bIter=true;if(!t.postData&&!t.getData)t.getData=this.GetReqData();var e=t.getData?t.getData.reqId:t.postData.reqId;var i=this,s=0;var n=function(n){function o(){var r=t.handler(i.GetRequestRes(e),n);if(r===false&&++s<20&&t.bIter)setTimeout(o,5);else i.ClearRequestRes(e)}setTimeout(o,50)};if(t.postData)BX.ajax.post(t.url,t.postData,n);else BX.ajax.get(t.url,t.getData,n)},GetRequestRes:function(t){if(top.BXHtmlEditorAjaxResponse[t]!=undefined)return top.BXHtmlEditorAjaxResponse[t];return{}},ClearRequestRes:function(t){if(top.BXHtmlEditorAjaxResponse){top.BXHtmlEditorAjaxResponse[t]=null;delete top.BXHtmlEditorAjaxResponse[t]}},GetReqData:function(t,e){if(!e)e={};if(t)e.action=t;e.sessid=BX.bitrix_sessid();e.bx_html_editor_request="Y";e.reqId=Math.round(Math.random()*1e6);return e},GetTemplateId:function(){return this.templateId},GetSiteId:function(){return this.config.siteId},GetComponentFilter:function(){return this.componentFilter},GetTemplateParams:function(){return this.templates[this.templateId]},GetTemplateStyles:function(){var t=this.templates[this.templateId]||{};return t.STYLES||""},ApplyTemplate:function(t){if(this.templateId!==t){if(this.templates[t]){this.templateId=t;var e=this.templates[t],i,s=this.sandbox.GetDocument(),n=s.head||s.getElementsByTagName("HEAD")[0],o=n.getElementsByTagName("STYLE"),r=n.getElementsByTagName("LINK");for(i=0;i<o.length;i++){if(o[i].getAttribute("data-bx-template-style")=="Y")BX.cleanNode(o[i],true)}i=0;while(i<r.length){if(r[i].getAttribute("data-bx-template-style")=="Y"){BX.remove(r[i],true)}else{i++}}if(e["STYLES"]){n.appendChild(BX.create("STYLE",{props:{type:"text/css"},text:e["STYLES"]},s)).setAttribute("data-bx-template-style","Y")}if(e&&e["EDITOR_STYLES"]){for(i=0;i<e["EDITOR_STYLES"].length;i++){n.appendChild(BX.create("link",{props:{rel:"stylesheet",href:e["EDITOR_STYLES"][i]+"_"+this.cssCounter++}},s)).setAttribute("data-bx-template-style","Y")}}this.On("OnApplySiteTemplate",[t])}else{var a=this;this.Request({getData:this.GetReqData("load_site_template",{site_template:t}),handler:function(e){a.templates[t]=e;a.ApplyTemplate(t)}})}}},FormatHtml:function(e,i){if(e.length<this.MAX_HANDLED_FORMAT_LENGTH||i===true){if(!this.formatter)this.formatter=new t.BXHtmlEditor.BXCodeFormatter(this);var s=(new Date).getTime();e=this.formatter.Format(e);var n=(new Date).getTime();if(n-s>this.MAX_HANDLED_FORMAT_TIME)this.MAX_HANDLED_FORMAT_LENGTH-=5e3}return e},GetFontFamilyList:function(){if(!this.fontFamilyList){this.fontFamilyList=[{value:["Times New Roman","Times"],name:"Times New Roman"},{value:["Courier New"],name:"Courier New"},{value:["Arial","Helvetica"],name:"Arial / Helvetica"},{value:["Arial Black","Gadget"],name:"Arial Black"},{value:["Tahoma","Geneva"],name:"Tahoma / Geneva"},{value:"Verdana",name:"Verdana"},{value:["Georgia","serif"],name:"Georgia"},{value:"monospace",name:"monospace"}];this.On("GetFontFamilyList",[this.fontFamilyList])}return this.fontFamilyList},CheckCurrentStatus:function(t){var e,i,s,n,o=this.GetActiveActions();if(t===false){for(i in o){if(o.hasOwnProperty(i)&&this.action.IsSupported(i)){e=o[i];e.control.SetValue(false,null,i)}}}if(!this.iframeView.IsFocused())return this.On("OnIframeBlur");var r=this.selection.GetRange();if(!r||!r.isValid())return this.On("OnIframeBlur");for(i in o){if(o.hasOwnProperty(i)&&this.action.IsSupported(i)){e=o[i];s=this.action.CheckState(i,e.value);n=e.control.GetValue();if(s){e.control.SetValue(true,s,i)}else{e.control.SetValue(false,null,i)}}}},RegisterCheckableAction:function(t,e){if(!this.checkedActionList)this.checkedActionList={};this.checkedActionList[t]=e},GetActiveActions:function(){return this.checkedActionList},SaveOption:function(t,e){BX.userOptions.save("html_editor",this.config.settingsKey,t,e)},GetCurrentCssClasses:function(t){return this.styles.GetCSS(this.templateId,this.templates[this.templateId].STYLES,this.templates[this.templateId].PATH||"",t||false)},GetStylesDescription:function(t){if(!t)t=this.templateId;var e={};if(t&&this.templates[t]){e=this.templates[t].STYLES_TITLE||{}}return e},IsInited:function(){return!!this.inited},IsContentChanged:function(){var t=this.config.content.replace(/[\s\n\r\t]+/gi,""),e=this.GetContent().replace(/[\s\n\r\t]+/gi,"");return t!=e},IsSubmited:function(){return this.isSubmited},OnSubmit:function(){if(!this.isSubmited&&this.dom.cont.style.display!=="none"){this.RemoveCursorNode();this.isSubmited=true;if(this.iframeView.IsFocused())this.On("OnIframeBlur");this.On("OnSubmit");this.SaveContent()}},AllowBeforeUnloadHandler:function(){this.beforeUnloadHandlerAllowed=true},DenyBeforeUnloadHandler:function(){this.beforeUnloadHandlerAllowed=false},Destroy:function(){if(this.sandbox)this.sandbox.Destroy();if(this.Check())BX.remove(this.dom.cont)},Check:function(){return this.dom.cont&&BX.isNodeInDom(this.dom.cont)},IsVisible:function(){return this.Check()&&this.dom.cont.offsetWidth>0},GetLastSpecialchars:function(){var t=["&cent;","&sect;","&euro;","&pound;","&yen;","&copy;","&reg;","&laquo;","&raquo;","&deg;","&plusmn;","&para;","&hellip;","&prime;","&Prime;","&trade;","&asymp;","&ne;","&lt;","&gt;"];if(this.config.lastSpecialchars&&typeof this.config.lastSpecialchars=="object"&&this.config.lastSpecialchars.length>1){return this.config.lastSpecialchars}else{return t}},GetIframeElement:function(t){var e=this.GetIframeDoc();return e?e.getElementById(t):null},RegisterDialog:function(e,i){t.BXHtmlEditor.dialogs[e]=i},SetConfigHeight:function(t){this.config.height=t;if(this.IsExpanded()){this.savedSize.configHeight=t;this.savedSize.height=t}},CheckBrowserCompatibility:function(){return!(BX.browser.IsOpera()||BX.browser.IsIE8()||BX.browser.IsIE7()||BX.browser.IsIE6()||!document.querySelectorAll)},GetCursorHtml:function(){return'<span id="bx-cursor-node"> </span>'},SetCursorNode:function(t){if(!t)t=this.selection.GetRange();this.RemoveCursorNode();this.selection.InsertHTML(this.GetCursorHtml(),t)},RestoreCursor:function(){var t=this.GetIframeElement("bx-cursor-node");if(t){this.selection.SetAfter(t);BX.remove(t)}},RemoveCursorNode:function(){if(this.synchro.IsFocusedOnTextarea()){}else{var t=this.GetIframeElement("bx-cursor-node");if(t){this.selection.SetAfter(t);BX.remove(t)}}},AddButton:function(e){if(e.compact==undefined)e.compact=false;if(e.toolbarSort==undefined)e.toolbarSort=301;if(e.hidden==undefined)e.hidden=false;var i=function(t,s){i.superclass.constructor.apply(this,arguments);this.id=e.id;this.title=e.name;if(e.iconClassName)this.className+=" "+e.iconClassName;if(e.action)this.action=e.action;if(e.disabledForTextarea!==undefined)this.disabledForTextarea=e.disabledForTextarea;this.Create();if(e.src)this.pCont.firstChild.style.background='url("'+e.src+'") no-repeat scroll 0 0';if(s)s.appendChild(this.GetCont())};BX.extend(i,t.BXHtmlEditor.Button);if(e.handler)i.prototype.OnClick=e.handler;t.BXHtmlEditor.Controls[e.id]=i;BX.addCustomEvent(this,"GetControlsMap",(function(t){t.push({id:e.id,compact:e.compact,hidden:e.hidden,sort:e.toolbarSort,checkWidth:e.checkWidth==undefined?true:!!e.checkWidth,offsetWidth:e.offsetWidth||32})}))},AddCustomParser:function(t){if(this.phpParser&&this.phpParser.AddCustomParser){this.phpParser.AddCustomParser(t)}else{var e=this;BX.addCustomEvent("OnEditorInitedAfter",(function(){e.phpParser.AddCustomParser(t)}))}},AddParser:function(t){if(t&&t.name&&typeof t.obj=="object"){this.parser.specialParsers[t.name]=t.obj}},InsertHtml:function(t,e){if(!this.synchro.IsFocusedOnTextarea()){this.Focus();if(this.selection.lastCheckedRange&&this.selection.lastCheckedRange.range&&!e){try{this.selection.SetSelection(this.selection.lastCheckedRange.range)}catch(t){}}if(!e){e=this.selection.GetRange()}if(!e&&this.selection.lastRange)e=this.selection.lastRange;if(e){if(!e.collapsed&&e.startContainer==e.endContainer&&e.startContainer.nodeName!=="BODY"){var i=this.util.CheckSurrogateNode(e.startContainer);if(i){this.selection.SetAfter(i)}}this.selection.InsertHTML(t,e);this.selection.ScrollIntoView()}}},ParseContentFromBbCode:function(t){if(this.bbCode){t=this.bbParser.Parse(t);t=this.Parse(t,true,true)}return t},LoadFileDialogs:function(t){var e=this;this.Request({getData:this.GetReqData("load_file_dialogs",{editor_id:this.id}),handler:function(i,s){s=BX.util.trim(s);e.dom.fileDialogsWrap.innerHTML=s;e.fileDialogsLoaded=true;setTimeout(t,100)}})},InitAutosaveHandlers:function(){var t=this,e=this.dom.form;try{BX.addCustomEvent(this,"OnContentChanged",(function(){e.BXAUTOSAVE.Init()}));BX.addCustomEvent(e,"onAutoSave",(function(e,i){if(t.IsShown()&&!t.IsSubmited()){i[t.config.inputName]=t.GetContent()}}));BX.addCustomEvent(e,"onAutoSaveRestore",(function(e,i){if(t.IsShown()){t.SetContent(i[t.config.inputName],true)}}))}catch(t){}},InitImageUploader:function(){if(this.config.uploadImagesFromClipboard!==false){var t=this.config.actionUrl;t+=(t.indexOf("?")!==-1?"&":"?")+"action=uploadfile";this.imageUploader=BX.Uploader.getInstance({id:this.CID,streams:1,allowUpload:"A",uploadFileUrl:t,uploadMethod:"immediate",showImage:false,sortItems:false,input:null,placeHolder:null,uploadFormData:"N"});var e=this;BX.addCustomEvent(this,"OnImageDataUriHandle",(function(t,i){var s=BX.UploaderUtils.dataURLToBlob(i.src);if(s&&s.size>0&&s.type.indexOf("image/")==0){s.name=s.name||i.title||this.GetDefaultImageName()+"."+s.type.substr(6);s.uniqId=i.uniqId;s.editorBase64Src=i.src;e.imageUploader.onChange([s])}}));BX.addCustomEvent(this.imageUploader,"onFileIsCreated",(function(t,i){BX.addCustomEvent(i,"onUploadDone",(function(t,i){e.HandleImageDataUriCaughtUploadedCallback({src:t.file.editorBase64Src,uniqId:t.file.uniqId},{src:i.file.uploadedPath})}))}))}},GetDefaultImageName:function(){var t={value:false};this.On("OnGetDefaultUploadImageName",[t]);if(!t.value){t.value="content-img"}return t.value},InitClipboardHandler:function(){var t=this;this.base64Images=[];function e(i){t.pasteCheckItteration++;var s;for(s=0;s<i.length;s++){if(!i[s].getAttribute("data-bx-paste-check")){if(i[s].complete)t.CheckImage(i[s],false);else BX.bind(i[s],"load",BX.proxy(t.CheckImage,t));i[s].setAttribute("data-bx-paste-check","Y")}}if(t.pasteCheckItteration===1)setTimeout((function(){e(i)}),500);else if(t.pasteCheckItteration<15)setTimeout((function(){e(i)}),1e3)}BX.bind(this.iframeView.element,"paste",(function(i){var s=0,n=false,o=i.clipboardData;if(BX.browser.IsChrome()||BX.browser.IsSafari()){var r=navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);s=r?parseInt(r[2],10):Infinity}if(o&&o.items&&!BX.browser.IsFirefox()&&(!s||s<83)){var a=o.items[0];if(a&&a.type.indexOf("image/")>-1){var h=a.getAsFile();if(h){var l=new FileReader;l.readAsDataURL(h);l.onload=function(e){n=true;var i=new Image;i.src=e.target.result;setTimeout((function(){t.selection.InsertNode(i);t.HandleImageDataUri(i)}),100)}}}}if(!n){t.pasteCheckItteration=0;e(t.GetIframeDoc().body.getElementsByTagName("IMG"))}}));BX.removeCustomEvent(this,"OnImageDataUriCaughtUploaded",BX.proxy(this.HandleImageDataUriCaughtUploadedCallback,this));BX.addCustomEvent(this,"OnImageDataUriCaughtUploaded",BX.proxy(this.HandleImageDataUriCaughtUploadedCallback,this))},GetBase64Image:function(t){var e,i=false;for(e=0;e<this.base64Images.length;e++){if(this.base64Images[e].source==t){i=this.base64Images[e]}}return i},RegisterBase64Image:function(t,e){this.base64Images.push({source:t,status:e,index:this.base64Images.length})},CheckImage:function(t,e){if(t&&t.complete&&t.naturalHeight!==0){if(t.src.indexOf("blob:http")!==-1){t.src=this.GetImageBase64(t);t.title=""}if(t.src.indexOf("data:image/")!==-1){this.HandleImageDataUri(t)}if(e!==false){BX.unbind(t,"load",BX.proxy(this.CheckImage,this))}}},GetImageBase64:function(t){const e=document.createElement("canvas");let i=t.width;let s=t.height;if(i>1440){s=s*1440/i;i=1440}e.width=i;e.height=s;e.getContext("2d").drawImage(t,0,0,i,s);return e.toDataURL("image/jpeg",.7)},HandleImageDataUri:function(t){if(!t.getAttribute("data-bx-unique-id")){this.skipPasteControl=true;if(this.pasteControl.isOpened){this.pasteControl.Hide()}var e=this.GetBase64Image(t.src);if(e===false){this.RegisterBase64Image(t.src,"requested");var i="bx_base64_id_"+Math.round(Math.random()*1e9);t.setAttribute("data-bx-unique-id",i);t.removeAttribute("data-bx-orig-src");this.On("OnImageDataUriHandle",[this,{src:t.src,title:t.title||"",uniqId:i}])}else{if(e.status=="uploaded"){this.HandleImageDataUriCaughtUploadedCallback({src:t.src,title:t.title||"",uniqId:e.uniqId},{src:e.fileSrc},e.htmlForInsert||null)}}}},HandleImageDataUriCaughtUploadedCallback:function(t,e,i){if(t&&t.uniqId&&e&&e.src){var s=this.GetBase64Image(t.src);if(s&&!s.fileSrc){s.status="uploaded";s.uniqId=t.uniqId;s.fileSrc=e.src;s.htmlForInsert=i}var n,o,r=this.GetIframeDoc().body.getElementsByTagName("IMG");for(n=0;n<r.length;n++){o=r[n];if(o.getAttribute("data-bx-unique-id")==t.uniqId||o.getAttribute("src")==t.src){if(i&&i.replacement){this.selection.SetAfter(o);this.selection.InsertHTML(i.replacement);BX.remove(o);if(i.callback){setTimeout(i.callback,300)}}else{o.src=e.src;o.setAttribute("src",e.src);o.setAttribute("data-bx-orig-src",e.src);o.removeAttribute("data-bx-paste-check");o.removeAttribute("data-bx-unique-id")}}}}this.skipPasteControl=false}};t.BXEditor=i;function s(t,e){this.callback=t||BX.DoNothing;this.config=e||{};this.editor=this.config.editor;this.iframe=this.CreateIframe();this.bSandbox=false;this.windowProperties=["parent","top","opener","frameElement","frames","localStorage","globalStorage","sessionStorage","indexedDB"];this.windowProperties2=["open","close","openDialog","showModalDialog","alert","confirm","prompt","openDatabase","postMessage","XMLHttpRequest","XDomainRequest"];this.documentProperties=["referrer","write","open","close"]}s.prototype={GetIframe:function(){return this.iframe},GetWindow:function(){this._readyError()},GetDocument:function(){this._readyError()},Destroy:function(){var t=this.GetIframe();t.parentNode.removeChild(t)},_readyError:function(){throw new Error("Sandbox: Sandbox iframe isn't loaded yet")},CreateIframe:function(){var t=this,e=BX.create("IFRAME",{props:{className:"bx-editor-iframe",frameborder:0,allowtransparency:"true",width:0,height:0,marginwidth:0,marginheight:0}});e.onload=function(){e.onreadystatechange=e.onload=null;t.OnLoadIframe(e)};e.onreadystatechange=function(){if(/loaded|complete/.test(e.readyState)){e.onreadystatechange=e.onload=null;t.OnLoadIframe(e)}};this.config.cont.appendChild(e);return e},OnLoadIframe:function(t){if(BX.isNodeInDom(t)){this.InitIframe(t,(()=>{var e=t.contentWindow;var i=e.document;e.onerror=function(t,e,i){throw new Error("Sandbox: "+t,e,i)};if(this.bSandbox){var s,n;for(s=0,n=this.windowProperties.length;s<n;s++){this._unset(e,this.windowProperties[s])}for(s=0,n=this.windowProperties2.length;s<n;s++){this._unset(e,this.windowProperties2[s],BX.DoNothing())}for(s=0,n=this.documentProperties.length;s<n;s++){this._unset(i,this.documentProperties[s])}this._unset(i,"cookie","",true)}this.loaded=true;this.callback(this);this.editor.On("OnAfterIframeInit",[this.editor])}))}},InitIframe:function(t,e){t=this.iframe||t;var i=t.contentWindow.document,s=this.GetHtml(this.config.stylesheets,this.editor.GetTemplateStyles());i.open("text/html","replace");i.write(s);i.close();this.GetWindow=function(){return t.contentWindow};this.GetDocument=function(){return t.contentWindow.document};const n=()=>{if(i.body){this.editor.On("OnIframeInit");if(typeof e==="function"){e()}}else{setTimeout(n,0)}};setTimeout(n,0)},GetHtml:function(t,e){let i="";if(this.editor.config.bodyClass||this.editor.IsExpanded()){let t=this.editor.config.bodyClass||"";if(this.editor.IsExpanded())t+=" fullscreen";i+=' class="'+BX.util.trim(t)+'"'}if(this.editor.config.bodyId){i+=' id="'+this.editor.config.bodyId+'"'}let s="";if(BX.Type.isStringFilled(this.editor.config.designTokens)){s+=this.editor.config.designTokens}if(BX.Type.isStringFilled(this.editor.config.headHtml)){s+=this.editor.config.headHtml}const n=this.editor.GetTemplateParams();if(n&&n["EDITOR_STYLES"]){for(let t=0;t<n["EDITOR_STYLES"].length;t++){s+='<link data-bx-template-style="Y" rel="stylesheet" href="'+n["EDITOR_STYLES"][t]+"_"+this.editor.cssCounter+++'">'}}t=typeof t==="string"?[t]:t;if(t){for(let e=0;e<t.length;e++){s+='<link rel="stylesheet" href="'+t[e]+'">'}}s+='<link rel="stylesheet" href="'+this.editor.config.cssIframePath+"_"+this.editor.cssCounter+++'">';if(typeof e==="string"){s+='<style type="text/css" data-bx-template-style="Y">'+e+"</style>"}if(BX.Type.isStringFilled(this.editor.config.fontSize)){s+=`<style>body { font-size: ${this.editor.config.fontSize}; }</style>`}if(this.editor.iframeCssText&&this.editor.iframeCssText.length>0){s+='<style type="text/css">'+this.editor.iframeCssText+"</style>"}return"<!DOCTYPE html><html><head>"+s+"</head><body"+i+"></body></html>"},_unset:function(t,e,i,s){try{t[e]=i}catch(t){}try{t.__defineGetter__(e,(function(){return i}))}catch(t){}if(s){try{t.__defineSetter__(e,(function(){}))}catch(t){}}if(!crashesWhenDefineProperty(e)){try{var n={get:function(){return i}};if(s){n.set=function(){}}Object.defineProperty(t,e,n)}catch(t){}}}};function n(e){this.editor=e;this.document=e.sandbox.GetDocument();BX.addCustomEvent(this.editor,"OnIframeReInit",BX.proxy((function(){this.document=this.editor.sandbox.GetDocument()}),this));t.rangy.init()}n.prototype={GetBookmark:function(){if(!this.editor.synchro.IsFocusedOnTextarea()){var t=this.GetRange();return t&&t.cloneRange()}return false},SetBookmark:function(t){if(t&&this.editor.currentViewName!=="code"){this.SetSelection(t)}},SaveBookmark:function(){this.lastRange=this.GetBookmark();return this.lastRange},GetLastRange:function(){if(this.lastRange)return this.lastRange},RestoreBookmark:function(){if(this.lastRange){this.SetBookmark(this.lastRange);this.lastRange=false}},SetBefore:function(t){var e=rangy.createRange(this.document);e.setStartBefore(t);e.setEndBefore(t);return this.SetSelection(e)},SetAfter:function(t){var e=rangy.createRange(this.document);e.setStartAfter(t);e.setEndAfter(t);return this.SetSelection(e)},SelectNode:function(t){if(!t)return;var e=rangy.createRange(this.document),i=t.nodeType===1,s="canHaveHTML"in t?t.canHaveHTML:t.nodeName!=="IMG",n=i?t.innerHTML:t.data,o=n===""||n===this.editor.INVISIBLE_SPACE,r=BX.style(t,"display"),a=r==="block"||r==="list-item";if((BX.browser.IsIE()||BX.browser.IsIE10()||BX.browser.IsIE11())&&t&&BX.util.in_array(t.nodeName.toUpperCase(),this.editor.TABLE_TAGS)){if(t.tagName=="TABLE"||t.tagName=="TBODY"){var h=t.rows[0],l=t.rows[t.rows.length-1];e.setStartBefore(h.cells[0]);e.setEndAfter(l.cells[l.cells.length-1])}else if(t.tagName=="TR"||t.tagName=="TH"){e.setStartBefore(t.cells[0]);e.setEndAfter(t.cells[t.cells.length-1])}else{e.setStartBefore(t);e.setEndAfter(t)}this.SetSelection(e);return e}if(o&&i&&s){try{t.innerHTML=this.editor.INVISIBLE_SPACE}catch(t){}}if(s)e.selectNodeContents(t);else e.selectNode(t);if(s&&o&&i){e.collapse(a)}else if(s&&o){e.setStartAfter(t);e.setEndAfter(t)}try{this.SetSelection(e)}catch(t){}return e},GetSelectedNode:function(t){var e,i,s;if(t&&this.document.selection&&this.document.selection.type==="Control"){s=this.document.selection.createRange();if(s&&s.length){e=s.item(0)}}if(!e){i=this.GetSelection();if(i.focusNode===i.anchorNode){e=i.focusNode}}if(!e){s=this.GetRange();e=s?s.commonparentContainer:this.document.body}if(e&&e.ownerDocument!=this.editor.GetIframeDoc()){e=this.document.body}return e},ExecuteAndRestore:function(t,e){var i=this.document.body,s=e&&i.scrollTop,n=e&&i.scrollLeft,o="_bx-editor-temp-placeholder",r='<span class="'+o+'">'+this.editor.INVISIBLE_SPACE+"</span>",a=this.GetRange(),h;if(!a){t(i,i);return}var l=a.createContextualFragment(r);a.insertNode(l);try{t(a.startContainer,a.endContainer)}catch(t){setTimeout((function(){throw t}),0)}if(document.querySelector){var d=this.document.querySelector("."+o);if(d){h=rangy.createRange(this.document);h.selectNode(d);h.deleteContents();this.SetSelection(h)}else{i.focus()}}if(e){i.scrollTop=s;i.scrollLeft=n}try{if(d&&d.parentNode)d.parentNode.removeChild(d)}catch(t){}},ExecuteAndRestoreSimple:function(t){var e=this.GetRange(),i=this.document.body,s,n,o,r,a;if(!e){t(i,i);return}r=e.getNodes([3]);n=r[0]||e.startContainer;o=r[r.length-1]||e.endContainer;a={collapsed:e.collapsed,startContainer:n,startOffset:n===e.startContainer?e.startOffset:0,endContainer:o,endOffset:o===e.endContainer?e.endOffset:o.length};try{t(e.startContainer,e.endContainer)}catch(t){setTimeout((function(){throw t}),0)}s=rangy.createRange(this.document);try{s.setStart(a.startContainer,a.startOffset)}catch(t){}try{s.setEnd(a.endContainer,a.endOffset)}catch(t){}try{this.SetSelection(s)}catch(t){}},InsertHTML:function(t,e){var i=rangy.createRangyRange(this.document),s=i.createContextualFragment(t),n=s.lastChild;this.InsertNode(s,e);if(n){this.SetAfter(n)}this.editor.On("OnInsertHtml")},InsertNode:function(t,e){if(!e||!e.isValid||!e.isValid())e=this.GetRange();if(e){e.insertNode(t)}this.editor.On("OnInsertHtml")},RemoveNode:function(t){this.editor.On("OnHtmlContentChangedByControl");var e=t.parentNode,i=t.nextSibling;BX.remove(t);this.editor.util.Refresh(e);if(i){this.editor.selection.SetBefore(i);this.editor.Focus()}this.editor.synchro.StartSync(100)},Surround:function(t,e){e=e||this.GetRange();if(e){try{e.surroundContents(t);this.SelectNode(t)}catch(i){t.appendChild(e.extractContents());e.insertNode(t)}}},ScrollIntoView:function(){var t,e=this,i=this.document,s=this.editor.sandbox.GetWindow(),n=i.documentElement.scrollHeight>i.documentElement.offsetHeight;if(n&&s){var o=i.__scrollIntoViewElement=i.__scrollIntoViewElement||function(){return BX.create("SPAN",{html:e.editor.INVISIBLE_SPACE},i)}(),r=0;this.InsertNode(o);if(o.parentNode){t=o;do{r+=t.offsetTop||0;t=t.offsetParent}while(t);o.parentNode.removeChild(o)}var a=BX.GetWindowScrollPos(i),h=BX.GetWindowInnerSize(i);if(r>a.scrollTop+h.innerHeight-40){s.scrollTo(a.scrollLeft,r)}}},SelectLine:function(){var e="getSelection"in t&&"modify"in t.getSelection();if(e){var i=this.document.defaultView,s=i.getSelection();s.modify("move","left","lineboundary");s.modify("extend","right","lineboundary")}else if(this.document.selection){var n=this.document.selection.createRange(),o=n.boundingTop,r=n.boundingHeight,a=this.document.body.scrollWidth,h,l,d,c,u;if(!n.moveToPoint)return;if(o===0){d=this.document.createElement("span");this.insertNode(d);o=d.offsetTop;d.parentNode.removeChild(d)}o+=1;for(c=-10;c<a;c+=2){try{n.moveToPoint(c,o);break}catch(t){}}h=o;l=this.document.selection.createRange();for(u=a;u>=0;u--){try{l.moveToPoint(u,h);break}catch(t){}}n.setEndPoint("EndToEnd",l);n.select()}},GetText:function(){var t=this.GetSelection();return t?t.toString():""},GetNodes:function(t,e){var i=this.GetRange();if(i)return i.getNodes([t],e);else return[]},GetRange:function(t,e){if(!t){if(!this.editor.iframeView.IsFocused()&&e!==false){var i=this.editor.GetIframeDoc(),s=i.documentElement.scrollTop||i.body.scrollTop,n=i.documentElement.scrollLeft||i.body.scrollLeft;this.editor.iframeView.Focus();var o=i.documentElement.scrollTop||i.body.scrollTop,r=i.documentElement.scrollLeft||i.body.scrollLeft;if(o!==s||r!==n){var a=this.editor.sandbox.GetWindow();if(a)a.scrollTo(n,s)}}t=this.GetSelection()}var h=t&&t.rangeCount&&t.getRangeAt(0);if(h.commonAncestorContainer&&h.commonAncestorContainer.nodeName=="#document"){h.selectNodeContents(this.editor.GetIframeDoc().body)}return h},GetSelection:function(t){return rangy.getSelection(t||this.document.defaultView||this.document.parentWindow)},SetSelection:function(t){var e=this.document.defaultView||this.document.parentWindow,i=rangy.getSelection(e);return i.setSingleRange(t)},GetStructuralTags:function(){if(!this.structuralTags){var t=/^TABLE/i;this.structuralTags={LI:/^UL|OL|MENU/i,DT:/^DL/i,DD:/^DL/i,TD:t,TR:t,TH:t,TBODY:t,TFOOT:t,THEAD:t,CAPTION:t,COL:t,COLGROUP:t};this.structuralTagsMatchRe=/^LI|DT|DD|TD|TR|TH|TBODY|CAPTION|COL|COLGROUP|TFOOT|THEAD/i}return this.structuralTags},SetCursorBeforeNode:function(t){},_GetNonTextLastChild:function(t){var e=t.lastChild;while(e.nodeType!=1&&e.previousSibling)e=e.previousSibling;return e.nodeType==1?e:false},_GetNonTextFirstChild:function(t){var e=t.firstChild;while(e.nodeType!=1&&e.nextSibling)e=e.nextSibling;return e.nodeType==1?e:false},_MoveCursorBeforeNode:function(t){var e=this,i,s,n;this.GetStructuralTags();if(t.nodeType==1&&t.nodeName.match(this.structuralTagsMatchRe)){n=this._GetNonTextFirstChild(t.parentNode)===t;if(!n){return}i=this.structuralTags[t.nodeName];if(i){s=BX.findParent(t,(function(t){if(t.nodeName.match(i)){return true}n=n&&e._GetNonTextFirstChild(t.parentNode)===t;return false}),t.ownerDocument.BODY);if(s&&n){t=s}else{return}}}this.SetInvisibleTextBeforeNode(t)},_MoveCursorAfterNode:function(t){var e=this,i,s,n;this.GetStructuralTags();if(t.nodeType==1&&t.nodeName.match(this.structuralTagsMatchRe)){n=this._GetNonTextLastChild(t.parentNode)===t;if(!n){return}i=this.structuralTags[t.nodeName];if(i){s=BX.findParent(t,(function(t){if(t.nodeName.match(i)){return true}n=n&&e._GetNonTextLastChild(t.parentNode)===t;return false}),t.ownerDocument.BODY);if(s&&n){t=s}else{return}}}this.SetInvisibleTextAfterNode(t)},SaveRange:function(t){var e=this.GetRange(false,t);if(e){this.lastCheckedRange={endOffset:e.endOffset,endContainer:e.endContainer,range:e}}else{setTimeout(BX.proxy(this.SaveRange,this),0)}},CheckLastRange:function(t){return this.lastCheckedRange&&this.lastCheckedRange.endOffset==t.endOffset&&this.lastCheckedRange.endContainer==t.endContainer},SetInvisibleTextAfterNode:function(t,e){var i=this.editor.util.GetInvisibleTextNode();if(t.nextSibling&&t.nextSibling.nodeType==3&&this.editor.util.IsEmptyNode(t.nextSibling)){this.editor.util.ReplaceNode(t.nextSibling,i)}else{this.editor.util.InsertAfter(i,t)}if(e){this.SetBefore(i)}else{this.SetAfter(i)}this.editor.Focus()},SetInvisibleTextBeforeNode:function(t){var e=this.editor.util.GetInvisibleTextNode();if(t.previousSibling&&t.previousSibling.nodeType==3&&this.editor.util.IsEmptyNode(t.previousSibling)){this.editor.util.ReplaceNode(t.previousSibling,e)}else{t.parentNode.insertBefore(e,t)}this.SetBefore(e);this.editor.Focus()},GetCommonAncestorForRange:function(t){return t.collapsed?t.startContainer:rangy.dom.getCommonAncestor(t.startContainer,t.endContainer)}};function o(t){this.isElementMerge=t.nodeType==1;this.firstTextNode=this.isElementMerge?t.lastChild:t;this.firstNode=t;this.textNodes=[this.firstTextNode]}o.prototype={DoMerge:function(){var t,e=this.textNodes.length,i=[],s,n,o;for(t=0;t<e;++t){s=this.textNodes[t];if(this.textNodes[t].nodeType!==3){return false}n=s.parentNode;i[t]=s.data;if(t){n.removeChild(s);if(!n.hasChildNodes())n.parentNode.removeChild(n)}}this.firstTextNode.data=o=i.join("");return o},GetLength:function(){var t=this.textNodes.length,e=0;while(t--)e+=this.textNodes[t].length;return e}};function r(t,e,i,s,n){this.editor=t;this.document=t.iframeView.document;this.tagNames=e||[defaultTagName];this.arStyle=i||{};this.cssClass=s||"";this.similarClassRegExp=null;this.normalize=n;this.applyToAnyTagName=false}r.prototype={GetStyledParent:function(t,e){e=e!==false;var i,s;while(t){if(t.nodeType==1){s=this.CheckCssStyle(t,e);i=this.CheckCssClass(t);if(BX.util.in_array(t.tagName.toLowerCase(),this.tagNames)&&i&&s)return t}t=t.parentNode}return false},CheckCssStyle:function(t,e){return this.editor.util.CheckCss(t,this.arStyle,e)},SimplifyNodesWithCss:function(t){var e,i=t.parentNode;if(i.childNodes.length==1){if(t.nodeName==i.nodeName){for(e in this.arStyle){if(this.arStyle.hasOwnProperty(e)&&t.style[e]){i.style[e]=t.style[e]}}this.editor.util.ReplaceWithOwnChildren(t)}else{for(e in this.arStyle){if(this.arStyle.hasOwnProperty(e)&&i.style[e]&&t.style[e]){i.style[e]=""}}}}},CheckCssClass:function(t){return!this.cssClass||this.cssClass&&BX.hasClass(t,this.cssClass)},PostApply:function(t,e){var i,s=t[0],n=t[t.length-1],r=[],a,h=s,l=n,d=0,c=n.length,u,f;for(i=0;i<t.length;++i){u=t[i];f=this.GetAdjacentMergeableTextNode(u.parentNode,false);if(f){if(!a){a=new o(f);r.push(a)}a.textNodes.push(u);if(u===s){h=a.firstTextNode;d=h.length}if(u===n){l=a.firstTextNode;c=a.GetLength()}}else{a=null}}var m=this.GetAdjacentMergeableTextNode(n.parentNode,true);if(m){if(!a){a=new o(n);r.push(a)}a.textNodes.push(m)}if(r.length){for(i=0;i<r.length;++i)r[i].DoMerge();e.setStart(h,d);e.setEnd(l,c)}t=e.getNodes([3]);for(i=0;i<t.length;++i){u=t[i];this.SimplifyNodesWithCss(u.parentNode)}},NormalizeNewNode:function(t,e){var i=t.parentNode;if(i&&i.nodeName!=="BODY"){var s=this.GetNonEmptyChilds(i),n=this.CheckCssStyle(i,false),o=this.CheckCssClass(i);if(s.length==1&&i.nodeName==t.nodeName&&n&&o){i.parentNode.insertBefore(t,i);BX.remove(i)}}return e},GetNonEmptyChilds:function(t){var e,i=t.childNodes,s=[];for(e=0;e<i.length;e++){if(i[e].nodeType==1||i[e].nodeType==3&&i[e].nodeValue!=""&&i[e].nodeValue!=this.editor.INVISIBLE_SPACE&&!i[e].nodeValue.match(/^[\s\n\r\t]+$/gi)){s.push(i[e])}}return s},GetAdjacentMergeableTextNode:function(t,e){var i=t.nodeType==3,s=i?t.parentNode:t,n,o=e?"nextSibling":"previousSibling";if(i){n=t[o];if(n&&n.nodeType==3){return n}}else{}return null},AreElementsMergeable:function(t,e){return rangy.dom.arrayContains(this.tagNames,(t.tagName||"").toLowerCase())&&rangy.dom.arrayContains(this.tagNames,(e.tagName||"").toLowerCase())&&t.className.replace(/\s+/g," ")==e.className.replace(/\s+/g," ")&&this.CompareNodeAttributes(t,e)},CompareNodeAttributes:function(t,e){if(t.attributes.length!=e.attributes.length)return false;var i,s=t.attributes.length,n,o,r;for(i=0;i<s;i++){n=t.attributes[i];r=n.name;if(r!="class"){o=e.attributes.getNamedItem(r);if(n.specified!=o.specified)return false;if(n.specified&&n.nodeValue!==o.nodeValue){return false}}}return true},CreateContainer:function(){var t=this.document.createElement(this.tagNames[0]);if(this.cssClass){t.className=this.cssClass}if(this.arStyle){for(var e in this.arStyle){if(this.arStyle.hasOwnProperty(e)){t.style[e]=this.arStyle[e]}}}return t},ApplyToTextNode:function(t){var e=t.parentNode,i;if(e.childNodes.length==1&&BX.util.in_array(e.tagName.toLowerCase(),this.tagNames)){if(this.cssClass){BX.addClass(e,this.cssClass)}if(this.arStyle){for(i in this.arStyle){if(this.arStyle.hasOwnProperty(i)){e.style[i]=this.arStyle[i]}}}}else{if(e.childNodes.length==1){if(this.cssClass&&BX.hasClass(e,this.cssClass)){BX.removeClass(e,this.cssClass)}if(this.arStyle){for(i in this.arStyle){if(this.arStyle.hasOwnProperty(i)&&e.style[i]){e.style[i]=""}}}}var s=this.CreateContainer();t.parentNode.insertBefore(s,t);s.appendChild(t)}},IsRemovable:function(t){return rangy.dom.arrayContains(this.tagNames,t.tagName.toLowerCase())&&BX.util.trim(t.className)==this.cssClass},IsAvailableTextNodeParent:function(t){return t&&t.nodeName&&t.nodeName!=="OL"&&t.nodeName!=="UL"&&t.nodeName!=="MENU"&&t.nodeName!=="TBODY"&&t.nodeName!=="TFOOT"&&t.nodeName!=="THEAD"&&t.nodeName!=="TABLE"&&t.nodeName!=="DL"},UndoToTextNode:function(t,e,i){if(!e.containsNode(i)){var s=e.cloneRange();s.selectNode(i);BX.isParentForNode(i,e.endContainer);if(e.endContainer.nodeName!=="BODY"&&s.isPointInRange(e.endContainer,e.endOffset)&&this.editor.util.IsSplitPoint(e.endContainer,e.endOffset)&&BX.isParentForNode(i,e.endContainer)){this.editor.util.SplitNodeAt(i,e.endContainer,e.endOffset);e.setEndAfter(i)}if(e.startContainer.nodeName!=="BODY"&&s.isPointInRange(e.startContainer,e.startOffset)&&this.editor.util.IsSplitPoint(e.startContainer,e.startOffset)&&BX.isParentForNode(i,e.startContainer)){i=this.editor.util.SplitNodeAt(i,e.startContainer,e.startOffset)}}if(i&&i.nodeName!="BODY"&&this.IsRemovable(i)){if(this.arStyle){for(var n in this.arStyle){if(this.arStyle.hasOwnProperty(n)&&i.style[n]){i.style[n]=""}}}if(!i.style.cssText||BX.util.trim(i.style.cssText)===""){this.editor.util.ReplaceWithOwnChildren(i)}else if(this.tagNames.length>1||this.tagNames[0]!=="span"){this.editor.util.RenameNode(i,"span")}}},ApplyToRange:function(t){var e=t.getNodes([3]);if(!e.length){try{var i=this.CreateContainer();t.surroundContents(i);t=this.NormalizeNewNode(i,t);this.SelectNode(t,i);return t}catch(t){}}t.splitBoundaries();e=t.getNodes([3]);if(!e.length&&t.collapsed&&t.startContainer==t.endContainer){var s=this.editor.util.GetInvisibleTextNode();this.editor.selection.InsertNode(s);e=[s]}if(e.length){var n;for(var o=0,r=e.length;o<r;++o){n=e[o];if(!this.GetStyledParent(n)&&this.IsAvailableTextNodeParent(n.parentNode)){this.ApplyToTextNode(n)}}t.setStart(e[0],0);n=e[e.length-1];t.setEnd(n,n.length);if(this.normalize){this.PostApply(e,t)}}return t},UndoToRange:function(t,e){var i=t.getNodes([3]),s,n;e=e!==false;if(i.length){t.splitBoundaries();i=t.getNodes([3])}else{var o=this.editor.util.GetInvisibleTextNode();t.insertNode(o);t.selectNode(o);i=[o]}var r,a,h=[];for(r=0,a=i.length;r<a;r++){h.push({node:i[r],nesting:this.GetNodeNesting(i[r])})}h=h.sort((function(t,e){return e.nesting-t.nesting}));for(r=0,a=h.length;r<a;r++){s=h[r].node;n=this.GetStyledParent(s,e);if(n){this.UndoToTextNode(s,t,n);t=this.editor.selection.GetRange()}}if(a==1){this.SelectNode(t,i[0])}else{t.setStart(i[0],0);t.setEnd(i[i.length-1],i[i.length-1].length);this.editor.selection.SetSelection(t);if(this.normalize){this.PostApply(i,t)}}return t},GetNodeNesting:function(t){return this.editor.util.GetNodeDomOffset(t)},SelectNode:function(t,e){var i=e.nodeType===1,s="canHaveHTML"in e?e.canHaveHTML:true,n=i?e.innerHTML:e.data,o=n===""||n===this.editor.INVISIBLE_SPACE;if(o&&i&&s){try{e.innerHTML=this.editor.INVISIBLE_SPACE}catch(t){}}t.selectNodeContents(e);if(o&&i){t.collapse(false)}else if(o){t.setStartAfter(e);t.setEndAfter(e)}},GetTextSelectedByRange:function(t,e){var i=e.cloneRange();i.selectNodeContents(t);var s=i.intersection(e);var n=s?s.toString():"";i.detach();return n},IsAppliedToRange:function(t,e){var i=[],s,n=t.getNodes([3]);e=e!==false;if(!n.length){s=this.GetStyledParent(t.startContainer,e);return s?[s]:false}var o,r;for(o=0;o<n.length;++o){r=this.GetTextSelectedByRange(n[o],t);s=this.GetStyledParent(n[o],e);if(r!=""&&!s){return false}else{i.push(s)}}return i},ToggleRange:function(t){return this.IsAppliedToRange(t)?this.UndoToRange(t):this.ApplyToRange(t)}};function a(t){this.editor=t;this.history=[this.editor.iframeView.GetValue()];this.position=1;this.document=t.sandbox.GetDocument();this.historyLength=30;BX.addCustomEvent(this.editor,"OnIframeReInit",BX.proxy((function(){this.document=this.editor.sandbox.GetDocument()}),this));this.Init()}a.prototype={Init:function(){var t=this;BX.addCustomEvent(this.editor,"OnHtmlContentChangedByControl",BX.delegate(this.Transact,this));BX.addCustomEvent(this.editor,"OnIframeNewWord",BX.delegate(this.Transact,this));BX.addCustomEvent(this.editor,"OnIframeKeyup",BX.delegate(this.Transact,this));BX.addCustomEvent(this.editor,"OnBeforeCommandExec",(function(e){if(e){t.Transact()}}));BX.addCustomEvent(this.editor,"OnIframeKeydown",BX.proxy(this.Keydown,this))},Keydown:function(t,e,i,s){if((t.ctrlKey||t.metaKey)&&!t.altKey){var n=e===this.editor.KEY_CODES["z"]&&!t.shiftKey,o=e===this.editor.KEY_CODES["z"]&&t.shiftKey||e===this.editor.KEY_CODES["y"];if(n){this.Undo();return BX.PreventDefault(t)}else if(o){this.Redo();return BX.PreventDefault(t)}}if(e!==this.lastKey){if(e===this.editor.KEY_CODES["backspace"]||e===this.editor.KEY_CODES["delete"]){this.Transact()}this.lastKey=e}},Transact:function(){var t=this.history[this.position-1],e=this.editor.iframeView.GetValue();if(e!==t){var i=this.history.length=this.position;if(i>this.historyLength){this.history.shift();this.position--}this.position++;this.history.push(e);this.CheckControls()}},Undo:function(){if(this.position>1){this.Transact();this.position--;this.Set(this.history[this.position-1]);this.editor.On("OnUndo");this.CheckControls()}},Redo:function(){if(this.position<this.history.length){this.position++;this.Set(this.history[this.position-1]);this.editor.On("OnRedo");this.CheckControls()}},Set:function(t){this.editor.iframeView.SetValue(t);this.editor.Focus(true)},CheckControls:function(){this.editor.On("OnEnableUndo",[this.position>1]);this.editor.On("OnEnableRedo",[this.position<this.history.length])}};function h(t){this.editor=t;this.arStyles={};this.sStyles=""}h.prototype={GetIframe:function(t){if(!this.cssIframe){this.cssIframe=this.CreateIframe(t)}return this.cssIframe},CreateIframe:function(t){this.cssIframe=document.body.appendChild(BX.create("IFRAME",{props:{className:"bx-editor-css-iframe"}}));this.iframeDocument=this.cssIframe.contentDocument||this.cssIframe.contentWindow.document;this.iframeDocument.open("text/html","replace");this.iframeDocument.write('<!DOCTYPE html><html><head><style type="text/css" data-bx-template-style="Y">'+t+"</style></head><body></body></html>");this.iframeDocument.close();return this.cssIframe},GetCSS:function(t,e,i,s){if(!this.arStyles[t]){if(!this.cssIframe){this.cssIframe=this.CreateIframe(e)}else{var n,o=this.iframeDocument,r=o.head||o.getElementsByTagName("HEAD")[0],a=r.getElementsByTagName("STYLE");for(n=0;n<a.length;n++){if(a[n].getAttribute("data-bx-template-style")=="Y")BX.cleanNode(a[n],true)}if(e){r.appendChild(BX.create("STYLE",{props:{type:"text/css"},text:e},o)).setAttribute("data-bx-template-style","Y")}}this.arStyles[t]=this.ParseCss()}var h=this.arStyles[t];if(s){var l=[],d;if(typeof s!="object"){s=[s]}s.push("DEFAULT");for(n=0;n<s.length;n++){d=s[n];if(h[d]&&typeof h[d]=="object"){l=l.concat(h[d])}}h=l}return h},ParseCss:function(){var t=this.iframeDocument,e=[],i={},s,n,o,r,a,h,l,d,c,u,f;if(!t.styleSheets){return i}var m=t.styleSheets,p=this.editor.GetStylesDescription();for(r=0,c=m.length;r<c;r++){s=m[r].rules?m[r].rules:m[r].cssRules;for(a=0,u=s.length;a<u;a++){if(s[a].type!=s[a].STYLE_RULE){continue}n=s[a].selectorText;o=n.split(",");for(h=0,f=o.length;h<f;h++){l=o[h].split(" ");l=l[l.length-1].trim();if(l.substr(0,1)=="."){l=l.substr(1);d="DEFAULT"}else{d=l.split(".");l=d.length>1?d[1]:"";d=d[0].toUpperCase()}if(!e[l]){e[l]=true;if(!i[d]){i[d]=[]}i[d].push({className:l,classTitle:p[l]||null,original:o[h],cssText:s[a].style.cssText})}}}}return i}};e={classes:{},tags:{b:{clean_empty:true},strong:{clean_empty:true},i:{clean_empty:true},em:{clean_empty:true},u:{clean_empty:true},del:{clean_empty:true},s:{rename_tag:"del"},strike:{rename_tag:"del"},h1:{},h2:{},h3:{},h4:{},h5:{},h6:{},span:{clean_empty:true},p:{},br:{},div:{},hr:{},nobr:{},code:{},section:{},figure:{},figcaption:{},fieldset:{},legend:{},menu:{rename_tag:"ul"},ol:{},ul:{},li:{},pre:{},table:{},tr:{},td:{check_attributes:{rowspan:"numbers",colspan:"numbers"}},tbody:{},tfoot:{},thead:{},th:{check_attributes:{rowspan:"numbers",colspan:"numbers"}},caption:{},col:{},colgroup:{},dl:{rename_tag:""},dd:{rename_tag:""},dt:{rename_tag:""},iframe:{},noindex:{},font:{rename_tag:"span",convert_attributes:{face:"fontFamily",size:"fontSize",color:"color"},replace_with_children:1},embed:{},noembed:{},object:{},param:{},sup:{},sub:{},address:{},nav:{},aside:{},article:{},main:{},acronym:{},abbr:{},label:{},time:{},small:{},big:{},details:{},summary:{},footer:{},video:{},source:{},audio:{},nofollow:{},title:{remove:1},area:{remove:1},command:{remove:1},noframes:{remove:1},bgsound:{remove:1},basefont:{remove:1},head:{remove:1},track:{remove:1},wbr:{remove:1},noscript:{remove:1},svg:{remove:1},keygen:{remove:1},meta:{remove:1},isindex:{remove:1},base:{remove:1},canvas:{remove:1},applet:{remove:1},spacer:{remove:1},frame:{remove:1},style:{remove:1},device:{remove:1},xml:{remove:1},nextid:{remove:1},link:{remove:1},script:{remove:1},comment:{remove:1},frameset:{remove:1},multicol:{rename_tag:"div"},map:{rename_tag:"div"},body:{rename_tag:"div"},html:{rename_tag:"div"},hgroup:{rename_tag:"div"},listing:{rename_tag:"div"},header:{rename_tag:"div"},rt:{rename_tag:"span"},xmp:{rename_tag:"span"},bdi:{rename_tag:"span"},progress:{rename_tag:"span"},dfn:{rename_tag:"span"},rb:{rename_tag:"span"},mark:{rename_tag:"span"},output:{rename_tag:"span"},marquee:{rename_tag:"span"},rp:{rename_tag:"span"},var:{rename_tag:"span"},tt:{rename_tag:"span"},blink:{rename_tag:"span"},plaintext:{rename_tag:"span"},kbd:{rename_tag:"span"},meter:{rename_tag:"span"},datalist:{rename_tag:"span"},samp:{rename_tag:"span"},bdo:{rename_tag:"span"},ruby:{rename_tag:"span"},ins:{rename_tag:"span"},optgroup:{rename_tag:"span"},form:{},option:{},select:{},textarea:{},button:{},input:{},dir:{rename_tag:"ul"},a:{},img:{check_attributes:{width:"numbers",alt:"alt",src:"url",height:"numbers"},add_class:{align:"align_img"}},q:{check_attributes:{cite:"url"}},blockquote:{check_attributes:{cite:"url"}},center:{rename_tag:"div",add_css:{textAlign:"center"}},cite:{}}}})(window);
//# sourceMappingURL=html-editor.map.js